<template>
  <div class="login-container">
    <search-header class="setUp-header">
      <template v-slot:left>
        <van-icon name="arrow-left" color="#aaa9a9" @click="goBack" />
      </template>
      <template v-slot:mid>登录</template>
      <template v-slot:right>
        <router-link to="/search"> <van-icon name="" /></router-link>
      </template>
    </search-header>
    <van-form @submit="onSubmit">
      <van-field
        v-model="username"
        name="用户名"
        label="用户名"
        placeholder="用户名"
        :rules="[{ required: true, message: '请填写用户名' }]"
      />
      <van-field
        v-model="password"
        type="password"
        name="密码"
        label="密码"
        placeholder="密码"
        :rules="[{ required: true, message: '请填写密码' }]"
      />
      <div style="margin: 16px">
        <van-button
          round
          block
          type="info"
          native-type="submit"
          color="chocolate"
          size="30px"
          >提交</van-button
        >
      </div>
    </van-form>
  </div>
</template>

<script>
import searchHeader from "../components/search-header.vue";
export default {
  components: { searchHeader },
  name: "Login",
  data() {
    return {
      username: "诗",
      password: "1234",
    };
  },
  methods: {
    onSubmit() {
      if (this.username.length == 0 || this.password.length == 0) {
        return false;
      }
      this.$notify("登录成功！");
      setTimeout(() => {
        this.$router.push({
          path: "/index/collection",
        });
      }, 1500);

      let userInfo = {
        uname: this.username,
        upass: this.password,
        isLogin: false,
      };

      localStorage.setItem("userInfo", JSON.stringify(userInfo));
    },
    goBack() {
      this.$router.back();
    },
  },
};
</script>

<style lang="less" scoped>
.login-container {
  padding-top: 40px;
  .van-cell {
    padding: 20px;
    font-size: 20px;
  }
  .van-button {
    font-size: 20px;
  }
}

.setUp-header {
  height: 40px;
  line-height: 40px;
  .van-icon {
    padding-top: 10px;
  }
}
</style>